﻿/**
new CheckBoxGroup({
'id':'box1',call:function(){},
'field':{'name':'networkType','value':'退网,新装'},
'group':[{'value':'退网','text':'退网&nbsp;'},{'value':'转网','text':'转网&nbsp;'},{'value':'新装','text':'新装&nbsp;'}]
});
*/
var CheckBoxGroupMap={};
function CheckBoxGroup(json)
{
	var container=document.getElementById(json.id);
	var fieldInput=document.createElement("input");
	var field=json.field;
	var boxName=field.name,boxValue=field.value;
	fieldInput.id=field.name;
	fieldInput.type="hidden";
	CheckBoxGroupMap[boxName]=this;
	for(var name in field)
	{
		fieldInput[name]=field[name];
		try
		{
			fieldInput.setAttribute(name,field[name]);
		}catch(e){}
	}
	container.appendChild(fieldInput);
	var group=json.group;
	var boxs=[],checkedCount=0;
	for(var i=0;i<group.length;i++)
	{
		var item=group[i];
		var box=document.createElement("input");
		box.type="checkbox";
		box.value=item.value;
		container.appendChild(box);
		if(boxValue.indexOf(item.value)>=0){box.checked=true;checkedCount++;}
		boxs.push(box);
		var textNode=document.createElement("label");
		textNode.innerHTML=item.text;
		container.appendChild(textNode);
		box.onclick=function()
		{
			setTimeout(function()
			{
				var count=0,values="";
				for(var i=0;i<boxs.length;i++)
				{
					if(boxs[i].checked)
					{
						if(count == 0){values=boxs[i].value;
						}else{values=values+";"+boxs[i].value;}
						count++;
					}
				}
				checkedCount=count;
				fieldInput.value=values;
				if(typeof(json.call)=="function"){json.call(values);}
			},100);
		}
	}
	if(typeof(json.call)=="function"){json.call(boxValue);}
}


